<template>
  <div>
      <p>用户：<input type="text" v-model="username"></p>
      <p>密码：<input type="text" v-model="password"></p>
      <p>邮箱：<input type="text" v-model="email"></p>
      <p>等级：<select v-model="grade">
        <option :value="i.id" v-for="i in list">{{i.username
            }}</option>
      </select></p>
      <p><button @click="btn">修改</button></p>
  </div>
</template>

<script>
    export default {
        name: "UpdateUser",
        data(){
          return{
            list:[],
            username:'',
            password:'',
            email:'',
            grade:'1',
            uid:this.$route.params.id
          }
        },
        methods:{
          btn(){
            let formdata=new FormData()
            formdata.append('username',this.username)
            formdata.append('password',this.password)
            formdata.append('email',this.email)
            formdata.append('uid',this.uid)
            formdata.append('grade',this.grade)
            axios({
              url:'http://127.0.0.1:8000/app01/update/',
              method:'post',
              data:formdata
            }).then(res=>{
              console.log(res)
            })
          }
        },
        created() {
          axios({
              url:'http://127.0.0.1:8000/app01/grade/',
              method:'get',
            }).then(res=>{
              console.log(res)
            this.list=res.data
          })
        }
    }
</script>

<style scoped>

</style>